﻿using Avalonia.Controls;
using ColorDocument.Avalonia;
using Markdown.Avalonia.Parsers;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

namespace Markdown.Avalonia.Plugins
{
    public abstract class BlockOverride2 : IBlockOverride
    {
        private readonly string _parserName;
        public string ParserName => _parserName;

        public BlockOverride2(string parserName)
        {
            _parserName = parserName;
        }

        public abstract IEnumerable<DocumentElement>? Convert2(string text, Match firstMatch, ParseStatus status, IMarkdownEngine2 engine, out int parseTextBegin, out int parseTextEnd);

        public IEnumerable<Control>? Convert(string text, Match firstMatch, ParseStatus status, IMarkdownEngine engine, out int parseTextBegin, out int parseTextEnd)
        {
            if (Convert2(text, firstMatch, status, engine.Upgrade(), out parseTextBegin, out parseTextEnd) is { } docs)
            {
                return docs.Select(d => d.Control);
            }
            return null;
        }
    }
}
